package com.cgbl.cg.ui.mine

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.cgbl.cg.BR
import com.cgbl.cg.R
import com.cgbl.cg.adapter.ResourceAdapter
import com.cgbl.cg.databinding.AppActivityResourceCenterBinding
import com.cgbl.cg.vm.mine.ResourceCenterViewModel
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.robot.base.model.ResourceBean
import com.robot.base.util.arouter.ARouterUtil

@Route(path = AppConstants.Router.Mine.A_MINE_RESOURCE_CENTER)
class ResourceCenterActivity :
    GLBaseActivity<AppActivityResourceCenterBinding, ResourceCenterViewModel>() {

    lateinit var resourceAdapter: ResourceAdapter

    override fun initComponents() {
        initTiterBar()
        initView()
    }

    override fun initData() {
        super.initData()
        viewModel.getMyNatural()
    }
    private fun initTiterBar() {
        val titleView = findViewById<TextView>(R.id.tv_title)
        val backView = findViewById<ImageView>(R.id.iv_back)
        titleView.text = "资源中心"
        backView.setOnClickListener { finish() }
    }

    private fun initView() {
        resourceAdapter = ResourceAdapter()
        binding.recyclerView.apply {
            layoutManager = LinearLayoutManager(this@ResourceCenterActivity)
            adapter = resourceAdapter
        }

        resourceAdapter.setOnItemClickListener { adapter, view, position ->
            ARouterUtil.goToActivity(AppConstants.Router.Mine.A_MINE_RESOURCE_PROFILE)
        }
    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.uc.refreshDataEvent.observe(this){
            resourceAdapter.setNewInstance(it as MutableList<ResourceBean>?)
        }
    }
    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_resource_center

    override fun initVariableId(): Int = BR.viewModel
}